package likouJava;

public class 乘积最大子数组 {
    public int maxProduct(int[] nums) {
        int n = nums.length;
        int maxF = nums[0];
        int minF = nums[0];
        int ans = nums[0];

        for (int i = 1; i < n; i++) {
            int x = nums[i];
            //当为复数时，最大值最小值交换
            if (x < 0){
                int temp = minF;
                minF = maxF;
                maxF = temp;
            }
            maxF = Math.max(x, maxF * x);
            minF = Math.min(x, minF * x);
            ans = Math.max(ans, maxF);
        }
        return ans;
    }


}
